Detailed explanation of iteration and merge methods in Javascript, and javascript merge
Iteration Method
In Javascript, iteration methods are especially important. In many cases, there are actual requirements. javascript provides five Iteration
JS has a lot of array operations, here is a common and infrequently used array operation methods.First, the creation of arraysThere are two ways to create an array, one through the literal and the other through the array constructor.1. Literalvar = [
Iterative methods
Iterative methods are particularly important in JavaScript, and in many cases there are actual requirements, JavaScript provides 5 iterative methods for us to operate, respectively:
Every () each item in the array uses the given
Array extensions in Javascript generally start with the object itself. Here we will introduce some items in the Array object. For example, indexOf is the index of the returned element in the Array, and-1 is returned if no element exists.
Recently I
indexOf
Returns the index of the element in the array, and returns-1. Similar to the IndexOf method of string.
If other browsers do not implement this method, you can implement compatibility with the following code:
Copy Code code as follows:
Determine if an object is an array: instanceof, Array.isarray ()You can use the instanceof operator for a Web page or for a global scope.if instanceof Array) { // Determine if value is an array }instanceof Operator It assumes that there is only
One, every (), runs the given function for each item in the array, and returns True if the function returns true for each item.var arr=[1,2,3,4,5,6,7,8,9];everyresult=arr.every (function(item,index,array) { return (item>2); The result of
(a) Js data typeDivided into basic data types and reference typesThe basic data types are null,undefined,boolen,number,string, and there is a complex data type Object. var var1 = "Xianrongbin", Var2 = false, Var3 = null, VAR4 = undefined, var5
variables, scopes, and memory issues
There are two types of execution environment-Global and local
The scope chain is longer, there are two cases: the catch block of the Try-catch statement, the WITH statement.
JavaScript does not
one about reference variables and basic data variables
In JS contains 5 basic data types: Number,boolean,String, null,undefined.The most notable thing here is string, which is a reference type in Java.These five basic data types are accessed by
JavaScript array type (array)
1. Introduce
1.1 Definition
The first method: through the constructor Array//Note: You can omit the new keyword
var colors = new Array ();
var colors = new Array;
var colors = new Array ();
The second method: the
This article examples for you to explain the JavaScript data types of relevant information for your reference, the specific contents are as follows
1. Reference typea value of a reference type is an instance of a reference type, which is a data
JS Processing Array Multiple methods
The data types in JS are divided into two main categories: the original type and the object type.
The original type includes: numeric value, String, Boolean, null, undefined
Object types include: objects are
To determine whether an object is an array: instanceof, Array.isarray ()
You can use the instanceof operator for a Web page or a global scope.
if (value instanceof Array) {//To determine if value is an array}Instanceof operator It assumes that
This article to share my JavaScript advanced programming Learning notes of the object and array reference types, related to JavaScript reference type knowledge, we look at it together.
1. Object type
Most reference type values are instances of
1. Array typeEach item of the ECMAScript array can hold any type of data, and the size of the array can be dynamically adjusted;(1) Creating an arrayFirst method: Array constructor var colors=new Array ();var colors1=new Array (20);var colors2=new
Then yesterday's study, I found some simple and fun way of the array.Merge method:ECMAScript 5 adds two methods for merging arrays: reduce () and reduceright () . Both of these methods will overlapAll the items of an algebraic group, and then
"2" Array typeEach item of the ECMAScript array can hold any type of data, and the size can be dynamically adjusted, which can automatically grow as the data is added to accommodate the new data.(1) Creating an array1 "Using the array constructorvar
ES6 to add a lot of methods to the array, I first summarize the previous method:1.array.isarray (): Detecting arraysvar arr = ['a','b','C' ]var'abc'console.log (Array.isarray (arr)) // trueconsole.log (Array.isarray (str))//false2.push (): Receive
Array in JavaScript
The arrays of ECMAScript are quite different from those in other languages. Although the array in ECMAScript is also an ordered list, each of its Arrays can save any type of data. The size of the ECMAScript array can be
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.